package main

import (
	"log"
	"os"
	"server_cluster/chat/chat_config"
	"server_cluster/chat/db"
	"server_cluster/chat/sharemem"
	"strconv"
)

func main() {
	chat_config.InitConfig()
	err := db.InitDB()
	if err != nil {
		log.Fatal("init db fail.")
		return
	}
	chat_config.GetConfig().RebuildSelf(db.Conn)

	shmid := sharemem.Get_myshm(&(sharemem.Myshm))
	if shmid <= 0 {
		log.Fatal("get myshm fail.")
		return
	}
	var myshm = sharemem.Myshm
	err = os.WriteFile("./shmid", []byte(strconv.Itoa(int(shmid))), 0644)
	if err != nil {
		panic(err)
	}

	if myshm.Status == 1 {
		log.Fatal("server is running.")
		return
	}

	sharemem.Init_myshm()
	log.Println("share-mem-init ok.")
}
